package cn.edu.ncu.housinghub.controller.agent;

import cn.edu.ncu.housinghub.dto.request.agent.ApplyAgentHouse;
import cn.edu.ncu.housinghub.entity.user.User;
import cn.edu.ncu.housinghub.service.AgentRentalService;
import cn.edu.ncu.housinghub.service.UserService;
import cn.edu.ncu.housinghub.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 代理所有可房源、查看已代理的房源、查看所有正在代理的房源、查看已完成出租的房源、管理租客预约、停止推广房源
 */
@RestController
@RequestMapping("/agent-rental")
public class AgentRentalController {
    @Autowired
    private AgentRentalService agentRentalService;
    @Autowired
    private UserService userService;
    /**
     * 获取所有可代理房源
     * @return
     */
    @GetMapping("getAllAgentRentalHouse")
    public Result getAllAgentHouse(){
        return Result.success(agentRentalService.getAllAgentRentalHouse());
    }
    /**
     * 获取某中介所有代理的房源
     * @return
     */
    @GetMapping("/getAllAgentHouse")
    public Result getAllAgentHouse(@RequestHeader("info")  String token){
        User user = userService.getUserByToken(token);
        return Result.success(agentRentalService.getAllAgentHouse(user.getId()));
    }
    /**
     * 获取某中介正在代理的房源
     */
    @GetMapping("/getAllAgentingHouse")
    public Result getAllAgentingHouse(@RequestHeader("info")  String token){
        User user = userService.getUserByToken(token);
        return Result.success(agentRentalService.getAllAgentingHouse(user.getId()));
    }
    /**
     * 获取某中介已经出租的房源
     */
    @GetMapping("/getAllAgentRentedHouse")
    public Result getAllAgentRentedHouse(@RequestHeader("info")  String token){
        User user = userService.getUserByToken(token);
        return Result.success(agentRentalService.getAllAgentRentedHouse(user.getId()));
    }
    /**
     * 申请推广某房源
     */
    @PostMapping("/applyAgentHouse")
    public Result applyAgentHouse(@RequestHeader("info") String token, @RequestBody ApplyAgentHouse applyAgentHouse){
        User user = userService.getUserByToken(token);
        return agentRentalService.applyAgentHouse(user.getId(), applyAgentHouse);
    }
}
